package com.shopmall.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shopmall.common.ResponseData;
import com.shopmall.system.entity.Role;
import com.shopmall.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys")
public class RoleController  extends ResponseData {
    @Autowired
    private IRoleService roleService;

    @PostMapping("/roleList")
    public ResponseData roleList(@RequestBody Role role){
        IPage<Role> roleIPage = roleService.pageList(role);
        return success(roleIPage);
    }

    @PostMapping("/addOrUpdate")
    public ResponseData addOrUpdate(@RequestBody Role role){
        int i = roleService.addOrUpdateRole(role);
        if(i>=0){
            return success(null);
        }
        return failed("提交失败");
    }

    @GetMapping("/del/{id}")
    public ResponseData addOrUpdate(@RequestParam @PathVariable Integer id){
        int i = roleService.deleteRoleById(id);
        if(i>=0){
            return success(null);
        }
        return failed("提交失败");
    }
}
